﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L02
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("输入数组元素的数量：");
            int n = int.Parse(Console.ReadLine());

            // 定义数组，并输入
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.Write("输入第{0}次元素的值:{1}", (i + 1), a[i]);
                a[i] = int.Parse(Console.ReadLine());
            }
            Output(a);
            Console.WriteLine("查找下标:{0}", Search(a));
            a = InsertSort(a);
            Console.ReadKey();
        }
        public static void Output(int[] str)
        {
            foreach (int sss in str)
                Console.WriteLine(sss);
        }
        public static int Search(int[] str)
        {
            int n = int.Parse(Console.ReadLine());
            int a = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == n)
                    a = i + 1;
            }
            return a;
        }
        private static int[] InsertSort(int[] array)
        {
            for (int i = 1; i < array.Length; i++)
            {
                int insertVal = array[i];
                int insertIndex = i - 1;
                while (insertIndex >= 0 && insertVal < array[insertIndex])
                {
                    array[insertIndex + 1] = array[insertIndex];
                    insertIndex--;
                }
                array[insertIndex + 1] = insertVal;
                Output(array);
                Console.WriteLine("第" + (i) + "趟");
            }
            return array;
        }
    }
}



n